var can1;
var can2;

var ctx1;
var ctx2;

var LASTTIME;
var DELTIME;

var canWidth; //画布-宽
var canHeight; //画布-高

var ane; //葵花

var foods; //食物
var bgImg = new Image();

var bigOne; // 大鱼

var MOUSEX;
var MOUSEY;

window.onload = FishGame; //入口文件
function FishGame() { //入口文件
	init(); //初始化文件
	LASTTIME = Date.now();
	DELTIME = 0;
	GameLoop(); //游戏刷新
}

function init() { //初始化文件
	can1 = document.getElementById('canvas1'); //fish dust ui circle
	can2 = document.getElementById('canvas2'); //background ane foods

	can1.addEventListener('mousemove', onMouseMove, false);

	ctx1 = can1.getContext('2d');
	ctx2 = can2.getContext('2d');

	bgImg.src = 'img/background.jpg';

	canWidth = can1.width;
	canHeight = can1.height;


	ane = new ane();
	ane.init();

	foods = new foods();
	foods.init();

	bigOne = new bigOne();
	bigOne.init();

	MOUSEX = canWidth * 0.5;
	MOUSEY = canHeight * 0.5;
}

function onMouseMove(e) { //鼠标位置-跟随
	if (e.offsetX || e.layerX) {
		MOUSEX = e.offsetX == undefined ? e.layerX : e.offsetX
	}
	if (e.offsetY || e.layerY) {
		MOUSEY = e.offsetY == undefined ? e.layerY : e.offsetY
	}
//	console.log(MOUSEX,MOUSEY)
}

function GameLoop() { //游戏刷新
	window.requestAnimFrame(GameLoop); //serInterval() setTImeOut()
	ctx1.clearRect(0, 0, canWidth, canHeight);
	var NOW = Date.now();
	DELTIME = NOW - LASTTIME > 0 ? NOW - LASTTIME : 0;
	LASTTIME = NOW;
	DrawImage1();
	ane.draw();
	foodsLimited();
	foods.draw();
	bigOne.draw();

}